﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Lifetime;


namespace _0122_RemotingActivatedClient
{
    class Program
    {
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel();
            ChannelServices.RegisterChannel(channel);

            ActivatedClientTypeEntry entry = new ActivatedClientTypeEntry(typeof(_0121_RemotingActivatedServer.MyServer), "tcp://localhost:9999");
            RemotingConfiguration.RegisterActivatedClientType(entry);

            _0121_RemotingActivatedServer.MyServer server =
                new _0121_RemotingActivatedServer.MyServer();

            //ClientSponsor cp = new ClientSponsor(TimeSpan.FromMinutes(5));
            //ILease lease = (ILease)RemotingServices.GetLifetimeService(server);
            //lease.Register(cp);

            RemotingInterface.ComplexObject result = server.doSomething("Hello world", 1, 1, new String[0]);
            Console.WriteLine("Server returns {0}", result.stringParam);

            System.Threading.Thread.Sleep(10000);
            result = server.doSomething("Goodbye world", 1, 1, new String[0]);
            Console.WriteLine("Server returns {0}", result.stringParam);

            Console.ReadLine();
        }
    }
}
